package com.zjdiepu.www.util;

import java.util.Date;

import com.zjdiepu.www.base.enums.type.SortFieldType;
import com.zjdiepu.www.common.util.DateUtil;
import com.zjdiepu.www.model.yw.request.YwBusinessQueryRequest;


/**
 * 项目名称：diepu-parent-commpent <br/> 
 * 类名称：YwExtHelper <br/>  
 * 类描述： 查询条件获取<br/>    
 * 创建人：xiongxiaotun <br/> 
 * 创建时间：2017年5月22日 下午12:29:13  <br/>   
 * 修改人：xiongxiaotun <br/> 
 * 修改时间：2017年5月22日 下午12:29:13   <br/>  
 * 修改备注：    <br/> 
 * @version V1.0   <br/>
 */
public class YwExtHelper {
	/**
	 * @author xiongxiaotun <br/>
	 * @Title: getExt  <br/>
	 * @Description: 获取查询条件 <br/>
	 * @param ywBusinessQueryRequest
	 * @param sortFieldType 排序字段类型
	 * @version V1.0  <br/>
	 */
	public static void initExt(YwBusinessQueryRequest ywBusinessQueryRequest,
			SortFieldType sortFieldType) {
		if (null == ywBusinessQueryRequest) {
			return;
		}

		Integer dayEnum = ywBusinessQueryRequest.getDayEnum();
		if (dayEnum != null) {
			Date now = new Date();
			switch (sortFieldType) {
			case SUBMIT_TIME:
				Date submitTimeEnd = ywBusinessQueryRequest.getSubmitTimeEnd();
				Date submitTimeStart = ywBusinessQueryRequest
						.getSubmitTimeStart();
				switch (dayEnum) {
				case 1: // 今天
					submitTimeStart = DateUtil.truncAndAddDays(now, 0);
					submitTimeEnd = DateUtil.truncAndAddDays(now, 0);
					break;
				case 2:// 昨天
					submitTimeStart = DateUtil.truncAndAddDays(now, -1);
					submitTimeEnd = DateUtil.truncAndAddDays(now, -1);
					break;
				case 3:// 近7天
					submitTimeStart = DateUtil.truncAndAddDays(now, -6);
					submitTimeEnd = DateUtil.truncAndAddDays(now, 0);
					break;
				case 5:// 近30天
					submitTimeStart = DateUtil.truncAndAddDays(now, -29);
					submitTimeEnd = DateUtil.truncAndAddDays(now, 0);
					break;
				default:
					break;
				}
				ywBusinessQueryRequest.setSubmitTimeStart(submitTimeStart);
				ywBusinessQueryRequest.setSubmitTimeEnd(submitTimeEnd);
				break;
			case LOAN_TIME:
				Date loanTimeEnd = ywBusinessQueryRequest.getLoanTimeEnd();
				Date loanTimeStart = ywBusinessQueryRequest.getLoanTimeStart();
				switch (dayEnum) {
				case 1:
					loanTimeStart = DateUtil.truncAndAddDays(now, 0);
					loanTimeEnd = DateUtil.truncAndAddDays(now, 0);
					break;
				case 2:
					loanTimeStart = DateUtil.truncAndAddDays(now, -1);
					loanTimeEnd = DateUtil.truncAndAddDays(now, -1);
					break;
				case 3:
					loanTimeStart = DateUtil.truncAndAddDays(now, -6);
					loanTimeEnd = DateUtil.truncAndAddDays(now, 0);
					break;
				case 5:
					loanTimeStart = DateUtil.truncAndAddDays(now, -29);
					loanTimeEnd = DateUtil.truncAndAddDays(now, 0);
					break;
				default:
					break;
				}
				ywBusinessQueryRequest.setLoanTimeStart(loanTimeStart);
				ywBusinessQueryRequest.setLoanTimeEnd(loanTimeEnd);
				break;
			case TIME_AUDIT_FINISH:
				Date timeAuditFinishEnd = ywBusinessQueryRequest
						.getTimeAuditFinishEnd();
				Date timeAuditFinishStart = ywBusinessQueryRequest
						.getTimeAuditFinishStart();
				switch (dayEnum) {
				case 1:
					timeAuditFinishStart = DateUtil.truncAndAddDays(now, 0);
					timeAuditFinishEnd = DateUtil.truncAndAddDays(now, 0);
					break;
				case 2:
					timeAuditFinishStart = DateUtil.truncAndAddDays(now, -1);
					timeAuditFinishEnd = DateUtil.truncAndAddDays(now, -1);
					break;
				case 3:
					timeAuditFinishStart = DateUtil.truncAndAddDays(now, -6);
					timeAuditFinishEnd = DateUtil.truncAndAddDays(now, 0);
					break;
				case 5:
					timeAuditFinishStart = DateUtil.truncAndAddDays(now, -29);
					timeAuditFinishEnd = DateUtil.truncAndAddDays(now, 0);
					break;
				default:
					break;
				}
				ywBusinessQueryRequest
						.setTimeAuditFinishStart(timeAuditFinishStart);
				ywBusinessQueryRequest
						.setTimeAuditFinishEnd(timeAuditFinishEnd);
				break;
			case OPERATOR_DATE:
				Date operatorDateEnd = ywBusinessQueryRequest
						.getOperatorDateEnd();
				Date operatorDateStart = ywBusinessQueryRequest
						.getOperatorDateStart();
				switch (dayEnum) {
				case 1:
					operatorDateStart = DateUtil.truncAndAddDays(now, 0);
					operatorDateEnd = DateUtil.truncAndAddDays(now, 0);
					break;
				case 2:
					operatorDateStart = DateUtil.truncAndAddDays(now, -1);
					operatorDateEnd = DateUtil.truncAndAddDays(now, -1);
					break;
				case 3:
					operatorDateStart = DateUtil.truncAndAddDays(now, -6);
					operatorDateEnd = DateUtil.truncAndAddDays(now, 0);
					break;
				case 5:
					operatorDateStart = DateUtil.truncAndAddDays(now, -29);
					operatorDateEnd = DateUtil.truncAndAddDays(now, 0);
					break;
				default:
					break;
				}
				ywBusinessQueryRequest.setOperatorDateStart(operatorDateStart);
				ywBusinessQueryRequest.setOperatorDateEnd(operatorDateEnd);
				break;
			default:
				break;
			}
		}

		ywBusinessQueryRequest.setSubmitTimeStart(DateUtil.truncAndAddDays(
				ywBusinessQueryRequest.getSubmitTimeStart(), 0));
		ywBusinessQueryRequest.setSubmitTimeEnd(DateUtil.truncAndAddDays(
				ywBusinessQueryRequest.getSubmitTimeEnd(), 1));

		ywBusinessQueryRequest.setLoanTimeStart(DateUtil.truncAndAddDays(
				ywBusinessQueryRequest.getLoanTimeStart(), 0));
		ywBusinessQueryRequest.setLoanTimeEnd(DateUtil.truncAndAddDays(
				ywBusinessQueryRequest.getLoanTimeEnd(), 1));

		ywBusinessQueryRequest.setTimeAuditFinishStart(DateUtil
				.truncAndAddDays(
						ywBusinessQueryRequest.getTimeAuditFinishStart(), 0));
		ywBusinessQueryRequest.setTimeAuditFinishEnd(DateUtil.truncAndAddDays(
				ywBusinessQueryRequest.getTimeAuditFinishEnd(), 1));

		ywBusinessQueryRequest.setOperatorDateStart(DateUtil.truncAndAddDays(
				ywBusinessQueryRequest.getOperatorDateStart(), 0));
		ywBusinessQueryRequest.setOperatorDateEnd(DateUtil.truncAndAddDays(
				ywBusinessQueryRequest.getOperatorDateEnd(), 1));
	}
}
